<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Class Toggle Example</title>
    <style>
        .box {
            width: 100px;
            height: 100px;
            background-color: blue;
        }
        .new-class {
            width: 200px;
            height: 200px;
            background-color: red;
        }
    </style>
</head>
<body>
    <div id="myDiv" class="box"></div>
    <button id="toggleButton">Toggle Class</button>
    <script>
        var element = document.getElementById('myDiv');
        var toggleButton = document.getElementById('toggleButton');

        toggleButton.addEventListener('click', function() {
            // 使用 classList.toggle 切换类
            element.classList.toggle('new-class');
        });
    </script>
</body>
</html>